//
//  LDMyResumeCellMyAdvantageInAll.swift
//  DingDongZP
//
//  Created by LeMac on 16/12/27.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit

class LDMyResumeCellMyAdvantageInAll: LDMyResumeBaseCellInAll {

    var strengthView:LDMyResumeCellMyAdvantageInAll_Row?
    var heightlightView:LDMyResumeCellMyAdvantageInAll_Row?
    
    var rowCount:Int?
    
    private var attr1H:CGFloat = 0
    private var attr2H:CGFloat = 0

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupView()
    }
    
    override func updateView() {
        
        strengthView?.model = model
        heightlightView?.model = model
        
        bgView?.bringSubviewToFront(editBtn!)
        
        setAttrH(model)
        
//        heightlightView?.backgroundColor = UIColor.redColor()
//        strengthView?.backgroundColor = UIColor.blueColor()
        
        heightlightView?.snp_updateConstraints(closure: { (make) in
            
            make.height.equalTo(attr1H + 80)
            
        })
    
        strengthView?.snp_updateConstraints(closure: { (make) in
            
            make.height.equalTo(attr2H + 80)
        })
        
    }
    
    
    override func getCellHeight(model:DDMyResumeModel) ->CGFloat {
        
        setAttrH(model)
        return attr1H + attr2H + 80 + 140
    }
    
    func getCellH(model:DDMyResumeModel) ->CGFloat {
        
        setAttrH(model)
        return attr1H + attr2H + 80 + 140
    }
    
    func setAttrH(model:DDMyResumeModel?) {
        
        if model == nil {
            return
        }
        
        let attr1 = LDMyResumeCellMyAdvantageInAll_Row.getTagDesc(model)
        
        
        attr1H = String.getHeightFormAttr(8, title: attr1, size: CGSizeMake(LDMyResumeCellMyAdvantageInAll_Row.textViewWidth, 1000), font: LDFont.Font14)
        
        let attr2 = model!.mystrengthstext ?? ""
        let newAttr2 = attr2.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
        attr2H = String.getHeightFormAttr(8, title: newAttr2, size: CGSizeMake(LDMyResumeCellMyAdvantageInAll_Row.textViewWidth, 1000), font: LDFont.Font14)
    }

    //
    func setupView() {
        
        title = "亮点优势"
        heightlightView = LDMyResumeCellMyAdvantageInAll_Row.init(type: .Heightlight)
        heightlightView?.title = "亮点"
        
        strengthView = LDMyResumeCellMyAdvantageInAll_Row.init(type: .Strength)
        strengthView?.title = "优势"
        
        bgView!.addSubview(strengthView!)
        bgView!.addSubview(heightlightView!)
        
        
        //增加左细线
        let divideLineV = UIView()
        divideLineV.backgroundColor = LDLineColorLightGray
        bgView!.addSubview(divideLineV)
        divideLineV.snp_makeConstraints(closure: { (make) in
            
            make.centerX.equalTo(heightlightView!.dotView!)
            make.top.equalTo(heightlightView!.dotView!.snp_bottom)
            make.bottom.equalTo(0)
            make.width.equalTo(0.5)
        })
        
        heightlightView?.snp_makeConstraints(closure: { (make) in
            
            
            make.top.equalTo(LDMargin_V*2)
            make.left.right.equalTo(0)
            make.height.equalTo(0)
            
        })
        
        strengthView?.snp_makeConstraints(closure: { (make) in
            
            make.top.equalTo(heightlightView!.snp_bottom)//.offset(LDMargin_V*3)
            make.left.right.equalTo(0)
            make.height.equalTo(0)
        })
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
